package com.mico.echart.monitor.controller;

import com.mico.echart.monitor.config.GlobalObject;
import com.mico.echart.monitor.model.Processes;
import com.mico.echart.monitor.model.Threads;
import com.mico.echart.monitor.system.SystemInfo;
import com.mico.echart.monitor.system.SystemInfoTest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import oshi.software.os.OSService;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author micocube
 * projectName: springboot-example
 * packageName: com.mico.echart.monitor.controller
 * email: ldscube@gmail.com
 * createTime: 2020-01-06 15:27
 * version: 0.1
 * description:
 */
@RestController
public class SystemInfoController {

    @RequestMapping("/System")
    public void getAllTread(HttpServletResponse response) throws IOException {
        Map<String, Object> computerSystem = SystemInfo.getComputerSystem();
        PrintWriter writer = response.getWriter();
        writer.println(GlobalObject.writeValueAsString(computerSystem, true));
        writer.flush();
        writer.close();
    }


    @RequestMapping("/Services")
    public void getAllProcess(HttpServletResponse response) throws IOException {
        Map<String, OSService[]> process = SystemInfo.getServices();
        PrintWriter writer = response.getWriter();
        writer.println(GlobalObject.writeValueAsString(process, true));
        writer.flush();
        writer.close();
    }


}
